1 package org.smartcomps.twister.engine.core.dynamic; 2 3 import junit.framework.TestCase; 4 import org.smartcomps.twister.engine.priv.core.dynamic.ExecutionContextFactory; 5 import org.smartcomps.twister.engine.priv.core.dynamic.ProcessInstanceFactory; 6 import org.smartcomps.twister.engine.priv.core.dynamic.ProcessInstance; 7 import org.smartcomps.twister.engine.priv.core.dynamic.ReceiveEC; 8 import org.smartcomps.twister.engine.priv.core.dynamic.ExecutionContext; 9 import org.smartcomps.twister.engine.core.definition.TestReceive; 10 import org.smartcomps.twister.engine.core.definition.TestProcess; 11 import org.smartcomps.twister.common.transaction.TransactionManager; 12 import org.smartcomps.twister.common.lifecycle.LifecycleManager; 13 import org.dom4j.DocumentHelper; 14 import org.dom4j.Element; 15 import org.dom4j.Document; 16 import net.sf.hibernate.tool.hbm2ddl.SchemaExport; 17 import net.sf.hibernate.cfg.Configuration; 18 19 import java.util.Map; 20 import java.util.HashMap; 21 22 public class TestReceiveEC extends TestCase { 23 24 public ReceiveEC testReceiveEC = null; 25 26 private TestReceive testReceive = new TestReceive(); 27 private TestProcess testProcess = new TestProcess(); 28 29 protected void setUp() throws Exception { 30 LifecycleManager.getLifecycleManager().createResources(); 31 LifecycleManager.getLifecycleManager().startResources(); 32 33 SchemaExport schemaExport = new SchemaExport(new Configuration().configure()); 34 schemaExport.create(true, true); 35 36 TransactionManager.beginTransaction(); 37 testProcess.testCreateWithCorrelation(); 38 // Receive is using the process created in TestProcess 39 testReceive.testCreate(); 40 } 41 42 protected void tearDown() throws Exception { 43 TransactionManager.commitTransaction(); 44 45 LifecycleManager.getLifecycleManager().stopResources(); 46 LifecycleManager.getLifecycleManager().destroyResources(); 47 } 48 49 public void testCreate() throws Exception { 50 Map corrProp = new HashMap(); 51 corrProp.put(TestProcess.CORRELATION_PROP1, "2578"); 52 corrProp.put(TestProcess.CORRELATION_PROP2, "12"); 53 ProcessInstance pi = ProcessInstanceFactory.createProcessInstance(TestReceive.receive.getProcess(), 54 TestProcess.CORRELATION_NAME, corrProp); 55 ReceiveEC receiveEC = (ReceiveEC) ExecutionContextFactory.createExecutionContext(TestReceive.receive, pi); 56 57 TransactionManager.commitTransaction(); 58 TransactionManager.beginTransaction(); 59 60 ProcessInstance createdInstance = ProcessInstanceFactory.findInstanceByCorrelation(TestProcess.CORRELATION_NAME, corrProp); 61 assertTrue("Instance child ec is not a ReceiveEC", 62 createdInstance.getChildExecutionContext() instanceof ReceiveEC); 63 testReceiveEC = (ReceiveEC) createdInstance.getChildExecutionContext(); 64 } 65 66 public void testExecuteWithoutVariable() throws Exception { 67 Map corrProp = new HashMap(); 68 corrProp.put(TestProcess.CORRELATION_PROP1, "2578"); 69 corrProp.put(TestProcess.CORRELATION_PROP2, "12"); 70 71 TestReceive.receive.execute(TestProcess.CORRELATION_NAME, corrProp); 72 73 TransactionManager.commitTransaction(); 74 TransactionManager.beginTransaction(); 75 76 ProcessInstance createdInstance = ProcessInstanceFactory.findInstanceByCorrelation(TestProcess.CORRELATION_NAME, corrProp); 77 assertTrue("Instance child is not a ReceiveEC", createdInstance.getChildExecutionContext() instanceof ReceiveEC); 78 ((ReceiveEC)createdInstance.getChildExecutionContext()).acknowledgeMessage(null); 79 80 TransactionManager.commitTransaction(); 81 TransactionManager.beginTransaction(); 82 83 ProcessInstance executedInstance = ProcessInstanceFactory.findInstanceByCorrelation(TestProcess.CORRELATION_NAME, corrProp); 84 assertEquals("Process is not completed after execution ended", ProcessInstance.COMPLETED, executedInstance.getStatus()); 85 assertEquals("Receive is not completed after execution ended", ExecutionContext.COMPLETED, executedInstance.getChildExecutionContext().getStatus()); 86 } 87 88 public void testExecuteWithVariable() throws Exception { 89 // Creating a dummy element to assign variable as incoming message 90 Document doc = DocumentHelper.createDocument(); 91 Element elmt = doc.addElement("message"); 92 elmt.addElement("test").addAttribute("test", "test"); 93 94 // Executing 95 Map corrProp = new HashMap(); 96 corrProp.put(TestProcess.CORRELATION_PROP1, "2578"); 97 corrProp.put(TestProcess.CORRELATION_PROP2, "12"); 98 99 TestReceive.receive.execute(TestProcess.CORRELATION_NAME, corrProp); 100 101 TransactionManager.commitTransaction(); 102 TransactionManager.beginTransaction(); 103 104 ProcessInstance createdInstance = ProcessInstanceFactory.findInstanceByCorrelation(TestProcess.CORRELATION_NAME, corrProp); 105 assertTrue("Instance child is not a ReceiveEC", createdInstance.getChildExecutionContext() instanceof ReceiveEC); 106 ((ReceiveEC)createdInstance.getChildExecutionContext()).acknowledgeMessage(doc); 107 108 TransactionManager.commitTransaction(); 109 TransactionManager.beginTransaction(); 110 111 ProcessInstance executedInstance = ProcessInstanceFactory.findInstanceByCorrelation(TestProcess.CORRELATION_NAME, corrProp); 112 assertEquals("Process is not completed after execution ended", ProcessInstance.COMPLETED, executedInstance.getStatus()); 113 assertEquals("Receive is not completed after execution ended", ExecutionContext.COMPLETED, executedInstance.getChildExecutionContext().getStatus()); 114 } 115 }

This page was automatically generated by Maven